package util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.util.Tool;

public class BaselineUtilities {

	public static List<BaselineTasking> processingConfigFile(String file) throws Exception {
		
		List<BaselineTasking> taskingSubmitted = new ArrayList<BaselineTasking>();
		BufferedReader in = new BufferedReader(new FileReader(file));

		String line;
		while ((line = in.readLine()) != null) {
			if (line.startsWith("tasking")) {
				taskingSubmitted.add(parseBaselineTaskingLine(line));
			}			
		}

		return taskingSubmitted;
	}
	
	public static BaselineTasking parseBaselineTaskingLine(String line) throws Exception {

			String[] components = line.split(";");

			String name = components[0];
			Class<? extends Tool> cls = (Class<? extends Tool>) Class.forName(components[1]);
			Long pause = Long.decode(components[2]);
			String[] args = components[3].split(",");

			return new BaselineTasking(name, cls, pause, args);

	}
	
	public static void pause(long time) {
		try {
			Thread.sleep(time);
		}
		catch (InterruptedException ex) {
			ex.printStackTrace();
		}
	}
}


